#!/bin/bash

function do_compile
{
    for dir in `ls`
    do  
        if [ -f $dir/build*.sh ] ; then
            cd $dir
               ./build*.sh
            cd -
        fi  
    done
}

function do_distclean
{
    for dir in `ls`
    do  
        if [ -f $dir/build*.sh ] ; then
            rm -rf ${dir}/${dir}*
        fi  
    done
}

if [ $# == 1 ] ; then 
    if [ $1 == "clean" ] ; then 
        rm -rf install
        exit;
    elif [ $1 == "distclean" ] ; then
        rm -rf install
        do_distclean
        exit;
    fi  

	# export cross compiler
	if echo $1 | grep "\-linux\-" > /dev/null 2>&1 ; then
		export CROSSTOOL=$1
		echo -e "\033[40;33m --W-- export cross compiler $CROSSTOOL \033[0m\n"
	fi
fi


do_compile

